<?php

	session_start();
	
	require_once("action/dao/UserDAO.php");
	
	abstract class CommonAction {
		
		public static $VISIBILITY_PUBLIC = 0;
		public static $VISIBILITY_MEMBER = 1;
		public static $VISIBILITY_ADMIN = 2;
		
		private $pageVisibility;
		
		public function __construct($pageVisibility) {
			$this->pageVisibility = $pageVisibility;
		}
		
		public function execute() {
			
			if (!isset($_SESSION["visibility"])) {
				$_SESSION["visibility"] = CommonAction::$VISIBILITY_PUBLIC;	
			}
			
			if ($_SESSION["visibility"] < $this->pageVisibility) {
				header("location:index.php");
				exit;
			}
			
			if (isset($_GET["logout"])) {
				MatchDAO::sauverStats();
				session_unset();
				session_destroy();
			}
			
			$this->executeAction();	
		}
	}